#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int arr[100010];
int n;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> arr[i];


	int ret = 0;
	int prevMin = arr[0];
	for (int i = 1; i < n;i++)
	{
		prevMin = min(prevMin, arr[i]);
		ret = max(ret, arr[i] - prevMin);
	}

	cout << ret << endl;

	return 0;
}